home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 11 / CU Amiga Magazine's Super CD-ROM 11 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-06].iso / www / http / www.amigasupport.com / software / arc / bmpdt.lha / BMPdt / Source / bmp.s < prev    next >
Text File  |  1996-04-21  |  7KB  |  343 lines

  1. ***************************************************************************
  2.  
  3. ; bmp.datatype v0.1 - 20/05/95 by Gunther Nikl - first version
  4.  
  5. ***************************************************************************
  6.  
  7. ; include stuff
  8.  
  9.         include    exec/types.i
  10.         include    exec/resident.i
  11.         include    exec/libraries.i
  12.         include    exec/initializers.i
  13.         include    lvo30/exec_lib.i
  14.         include    lvo30/utility_lib.i
  15.         include    lvo30/intuition_lib.i
  16.  
  17. ; import
  18.  
  19.         XREF    _GetBMP
  20.  
  21. ; specific defines
  22.  
  23. BMPVER        equ    40
  24. BMPREV        equ    5
  25.  
  26. PLAIN        set    1
  27.  
  28. ; macro stuff
  29.  
  30. CALL        MACRO
  31.         move.l    \2,a6
  32.         jsr    _LVO\1(a6)
  33.         ENDM
  34.  
  35. RECALL        MACRO
  36.         jsr    _LVO\1(a6)
  37.         ENDM
  38.  
  39. LIBVEC        macro
  40.         dc.w    \1-FuncTab
  41.         endm
  42.  
  43. ; class base
  44.  
  45.     STRUCTURE ClassBase,36
  46.  
  47.      ULONG    cb_SegList
  48.      ULONG    cb_SysBase
  49.      ULONG    cb_DosBase
  50.      ULONG    cb_IntBase
  51.      ULONG    cb_GfxBase
  52.      ULONG    cb_UtilityBase
  53.      ULONG    cb_DataTypesBase
  54.      ULONG    cb_SuperClassBase
  55.      ULONG    cb_BMPClass
  56.      STRUCT    cb_Lock,48
  57.  
  58.     LABEL cb_SIZEOF
  59.  
  60. LastBase    equ    cb_SuperClassBase
  61.  
  62. ***************************************************************************
  63.  
  64. start        moveq    #-1,d0
  65.         rts
  66.  
  67. ***************************************************************************
  68.  
  69. RomTag        dc.w    RTC_MATCHWORD
  70.         dc.l    RomTag
  71.         dc.l    EndTag
  72.         dc.b    RTF_AUTOINIT
  73.         dc.b    BMPVER
  74.         dc.b    NT_LIBRARY
  75.         dc.b    0
  76.         dc.l    LibName
  77.         dc.l    IdString
  78.         dc.l    InitTab
  79. EndTag
  80.  
  81. ;--------------------------------------------------------------------------
  82.  
  83. LibName        dc.b    'bmp.datatype',0
  84. IdString    dc.b    'bmp 40.5 (21.4.96) by Gunther Nikl',13,10,0
  85. DosName        dc.b    'dos.library',0
  86. IntName        dc.b    'intuition.library',0
  87. GfxName        dc.b    'graphics.library',0
  88. UtilityName    dc.b    'utility.library',0
  89. DataTypesName    dc.b    'datatypes.library',0
  90. SuperClassName    dc.b    'datatypes/'
  91. PicDTClassName    dc.b    'picture.datatype',0
  92.  
  93. ;--------------------------------------------------------------------------
  94.  
  95.         cnop    0,4
  96.  
  97. InitTab        dc.l    cb_SIZEOF
  98.         dc.l    FuncTab
  99.         dc.l    ResInfo
  100.         dc.l    InitFunc
  101.  
  102. ;--------------------------------------------------------------------------
  103.  
  104. FuncTab        dc.w    -1
  105.         LIBVEC    LibOpen
  106.         LIBVEC    LibClose
  107.         LIBVEC    LibExpunge
  108.         LIBVEC    LibExtFunc
  109.         LIBVEC    GetBMPEngine
  110.         dc.w    -1
  111.  
  112. ;--------------------------------------------------------------------------
  113.  
  114. ResInfo        INITBYTE LN_TYPE,NT_LIBRARY
  115.         INITLONG LN_NAME,LibName
  116.         INITBYTE LIB_FLAGS,(LIBF_SUMUSED!LIBF_CHANGED)
  117.         INITWORD LIB_VERSION,BMPVER
  118.         INITWORD LIB_REVISION,BMPREV
  119.         INITLONG LIB_IDSTRING,IdString
  120.         dc.w 0
  121.  
  122. ***************************************************************************
  123.  
  124.         cnop    0,4
  125.  
  126. InitFunc    move.l    a5,-(sp)
  127.         suba.l    a5,a5
  128.         cmp.w    #39,20(a6)
  129.         bcs.s    1$            ; wrong OS (not 3.x !)
  130.     IFND PLAIN
  131.         btst    #1,297(a6)
  132.         beq.s    1$            ; < 68020 !
  133.     ENDC
  134.         move.l    d0,a5
  135.         move.l    a0,cb_SegList(a5)    ; save seglist
  136.         move.l    a6,cb_SysBase(a5)    ; cache SysBase (speed!)
  137.         lea    cb_Lock(a5),a0
  138.         RECALL    InitSemaphore
  139. 1$        move.l    a5,d0            ; return LibBase (or NULL)
  140.         move.l    (sp)+,a5
  141.         rts
  142.  
  143. ;--------------------------------------------------------------------------
  144.  
  145. OpenLibs    lea    DosName(pc),a1        ; open all libraries
  146.         moveq    #cb_DosBase,d2
  147.         bsr.s    2$
  148.         beq.s    1$            ; no dos v39+!
  149.         lea    IntName(pc),a1
  150.         moveq    #cb_IntBase,d2
  151.         bsr.s    2$
  152.         beq.s    1$            ; no intuition v39+!
  153.         lea    GfxName(pc),a1
  154.         moveq    #cb_GfxBase,d2
  155.         bsr.s    2$
  156.         beq.s    1$            ; no graphics v39+!
  157.         lea    UtilityName(pc),a1
  158.         moveq    #cb_UtilityBase,d2
  159.         bsr.s    2$
  160.         beq.s    1$            ; no utility v39+!
  161.         lea    DataTypesName(pc),a1
  162.         moveq    #cb_DataTypesBase,d2
  163.         bsr.s    2$
  164.         beq.s    1$            ; no datatypes v39+!
  165.         lea    SuperClassName(pc),a1
  166.         moveq    #cb_SuperClassBase,d2
  167. 2$        moveq    #39,d0
  168.         RECALL    OpenLibrary
  169.         move.l    d0,0(a5,d2.w)        ; store library base
  170. 1$        rts
  171.  
  172. LibOpen        movem.l    d2/a2/a5/a6,-(sp)
  173.         move.l    a6,a5
  174.         addq.w    #1,32(a5)        ; one more user
  175.         and.b    #$f7,14(a5)
  176.         move.l    a5,d2
  177.         cmp.w    #1,32(a5)        ; first opener?
  178.         bne.s    1$
  179.         lea    cb_Lock(a5),a0
  180.         CALL    ObtainSemaphore,cb_SysBase(a5)
  181.         bsr.s    OpenLibs
  182.         beq.s    3$            ; failed...
  183.         move.l    a6,-(sp)
  184.         moveq    #0,d0
  185.         moveq    #0,d1
  186.         lea    LibName(pc),a0
  187.         lea    PicDTClassName(pc),a1
  188.         suba.l    a2,a2
  189.         CALL    MakeClass,cb_IntBase(a5)
  190.         move.l    d0,cb_BMPClass(a5)
  191.         beq.s    4$            ; no class...
  192.         move.l    d0,a0
  193.         lea    BMPDispatch(pc),a1
  194.         move.l    a1,8(a0)
  195.         move.l    a5,36(a0)
  196.         RECALL    AddClass        ; make it public
  197.         move.l    a5,d2
  198. 4$        move.l    (sp)+,a6
  199.         bne.s    2$            ; leave for good
  200. 3$        bsr.s    CloseLibs
  201.         subq.w    #1,32(a5)
  202.         moveq    #0,d2
  203. 2$        lea    cb_Lock(a5),a0
  204.         RECALL    ReleaseSemaphore    ; we are through
  205. 1$        move.l    d2,d0
  206.         movem.l    (sp)+,d2/a2/a5/a6
  207.         rts
  208.  
  209. ;--------------------------------------------------------------------------
  210.  
  211. LibClose    movem.l    d2/a5/a6,-(sp)
  212.         move.l    a6,a5
  213.         moveq    #0,d0            ; do not unload
  214.         tst.w    32(a5)
  215.         beq.s    3$
  216.         subq.w    #1,32(a5)        ; one less user
  217.         bne.s    1$
  218. 3$        lea    cb_Lock(a5),a0
  219.         CALL    ObtainSemaphore,cb_SysBase(a5)
  220.         move.l    cb_BMPClass(a5),d0    ; class created?
  221.         beq.s    2$
  222.         move.l    a6,-(sp)
  223.         move.l    d0,a0
  224.         CALL    FreeClass,cb_IntBase(a5) ; free it
  225.         clr.l    cb_BMPClass(a5)
  226.         move.l    (sp)+,a6
  227. 2$        bsr.s    CloseLibs        ; close all libs
  228.         lea    cb_Lock(a5),a0
  229.         RECALL    ReleaseSemaphore    ; free semaphore here...
  230.         moveq    #0,d0
  231.         btst    #3,14(a5)
  232.         beq.s    1$            ; do not expunge!
  233.         move.l    a5,a6
  234.         bsr.s    LibExpunge        ; remove library
  235. 1$        movem.l    (sp)+,d2/a5/a6
  236.         rts
  237.  
  238. CloseLibs    moveq    #LastBase-cb_SysBase,d2
  239. 2$        move.l    cb_SysBase(a5,d2.w),d0
  240.         beq.s    1$            ; no library to close
  241.         move.l    d0,a1
  242.         RECALL    CloseLibrary
  243.         clr.l    cb_SysBase(a5,d2.w)    ; clear entry
  244. 1$        subq.w    #4,d2
  245.         bne.s    2$            ; not ready
  246.         rts
  247.  
  248. ;--------------------------------------------------------------------------
  249.  
  250. LibExpunge    movem.l    a2/a5/a6,-(sp)
  251.         move.l    a6,a5
  252.         suba.l    a2,a2
  253.         or.b    #8,14(a5)        ; set LIBF_DELEXP
  254.         tst.w    32(a5)
  255.         bne.s    1$            ; still in use...
  256.         move.l    cb_SysBase(a5),a6
  257.         move.l    cb_SegList(a5),a2    ; get seglist
  258.         move.l    a5,a1
  259.         RECALL    Remove
  260.         move.l    a5,a1
  261.         moveq    #0,d0
  262.         move.w    16(a5),d0
  263.         suba.l    d0,a1
  264.         add.w    18(a5),d0
  265.         RECALL    FreeMem
  266. 1$        move.l    a2,d0            ; return SegList (or NULL)
  267.         movem.l    (sp)+,a2/a5/a6
  268.         rts
  269.  
  270. ;--------------------------------------------------------------------------
  271.  
  272. LibExtFunc    moveq    #0,d0            ; reserved library entry
  273.         rts
  274.  
  275. ;--------------------------------------------------------------------------
  276.  
  277. GetBMPEngine    move.l    cb_BMPClass(a6),d0    ; return class pointer
  278.         rts
  279.  
  280. ***************************************************************************
  281.  
  282. ; a0 -> a5 = class
  283. ; a2       = object
  284. ; a1 -> a3 = msg
  285.  
  286. BMPDispatch    movem.l    a2-a5,-(sp)
  287.         move.l    a0,a5            ; save class
  288.         move.l    a1,a3            ; save message
  289.         bsr.s    _doSuperMethod
  290.         move.l    d0,a2
  291.         move.l    a2,d0
  292.         beq.s    1$            ; NULL -> leave
  293.         cmpi.l    #$101,0(a3)
  294.         bne.s    1$            ; not OM_NEW !
  295.         move.l    4(a3),-(sp)        ; ops_AttrList
  296.         move.l    a2,-(sp)
  297.         move.l    a5,-(sp)
  298.         move.l    36(a5),a4
  299.         jsr    _GetBMP
  300.         lea    12(sp),sp
  301.         tst.l    d0
  302.         bne.s    1$            ; all ok !
  303.         move.l    a5,a0
  304.         pea    $102
  305.         move.l    sp,a1
  306.         bsr.s    _coerceMethod        ; dispose object
  307.         addq.w    #4,sp
  308.         suba.l    a2,a2            ; NULL
  309. 1$        move.l    a2,d0
  310.         movem.l    (sp)+,a2-a5
  311.         rts
  312.  
  313.         XDEF    _DoSuperMethod
  314.  
  315. _DoSuperMethod    move.l    a2,-(sp)        ; boopsi support
  316.         lea    8(sp),a1
  317.         movem.l    (a1)+,a0/a2
  318.         move.l    a2,d0
  319.         beq.s    1$
  320.         move.l    a0,d0
  321.         beq.s    1$
  322.         bsr.s    _doSuperMethod
  323. 1$        move.l    (sp)+,a2
  324.         rts
  325.  
  326. _doSuperMethod    move.l    24(a0),a0
  327. _coerceMethod    move.l    8(a0),-(sp)
  328.         rts
  329.  
  330. ;--------------------------------------------------------------------------
  331.  
  332.     IFD PLAIN
  333.  
  334.         XDEF    ___mulsi3
  335.  
  336. ___mulsi3:    movem.l    4(sp),d0/d1
  337.         move.l    cb_UtilityBase(a4),a0
  338.         jmp    _LVOSMult32(a0)
  339.  
  340.     ENDC
  341.  
  342.         end
  343.